package com.dliu.javadesign.create.prototype;

import java.util.HashMap;

/**
 * @author yanglei
 * date 2021/3/30 10:19
 */
public class AnimalCache {
    public static HashMap<Integer, Animal> caches = new HashMap<>();

    public static void loadCache(){
        Dog dog = new Dog();
        caches.put(dog.getId(), dog);

        Cat cat = new Cat();
        caches.put(cat.getId(), cat);
    }

    public static Animal getClone(Integer id){
        Animal animal = caches.get(id);
        return animal.clone();
    }

    public static void main(String[] args) {
        AnimalCache.loadCache();
        AnimalCache.getClone(2).voice();
    }
}
